<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>安装宝马App小部件</title>
</head>
<body>
<h1><a href="https://support.qq.com/products/362419/blog-archive" style="text-decoration: none;color:#666;">帮助文档</a>
    安装MyBMW小部件</h1>
<button id="copy" onclick="copy()"> 1.点击复制下方代码</button>
<textarea id="code" readonly>// Variables used by Scriptable.
    // These must be at the very top of the file. Do not edit.
    // icon-color: deep-blue; icon-glyph: magic;
    const FILE_MGR = FileManager[module.filename.includes('Documents/iCloud~') ? 'iCloud' : 'local']();
    
    if(!FILE_MGR.isDirectory(FILE_MGR.documentsDirectory() + '/modules')){
        FILE_MGR.createDirectory(FILE_MGR.documentsDirectory() + '/modules')
    }else{
    }
    
    const js = 'MyBmwEncryption.js'
    const REQ = new Request(`https://gitee.com/huchundong/qjl-rapv06-ffj/raw/master/${encodeURIComponent(js)}`);
    const RES = await REQ.load();
    FILE_MGR.write(FILE_MGR.joinPath(FILE_MGR.documentsDirectory(), '宝马App小部件.js'), RES);
    
    const js1 = 'InstallMyBmw.js'
    const REQ1 = new Request(`https://gitee.com/huchundong/qjl-rapv06-ffj/raw/master/${encodeURIComponent(js1)}`);
    const RES1 = await REQ1.load();
    FILE_MGR.write(FILE_MGR.joinPath(FILE_MGR.documentsDirectory(), '点击安装和更新宝马小部件.js'), RES1);
    
    const js2 = 'BmwEncrypt.js'
    const REQ2 = new Request(`https://gitee.com/huchundong/qjl-rapv06-ffj/raw/master/modules/${encodeURIComponent(js2)}`);
    const RES2 = await REQ2.load();
    FILE_MGR.write(FILE_MGR.joinPath(FILE_MGR.documentsDirectory() + '/modules/', '_' + js2), RES2);
    FILE_MGR.remove(module.filename);
    Safari.open("scriptable:///open?scriptName=" + encodeURIComponent('宝马App小部件'));
    </textarea>
<p>打开 Scriptable，点击右上角➕，粘贴，运行 ▶️</p>
<a id="open" href="scriptable:///add?scriptName=InstallUpdateMyBmw"> 2. 点击打开 Scriptable</a>
</body>
<style>
    body {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
    }

    #copy, #open {
        width: 200px;
        height: 50px;
        background-color: green;
        color: #FFF;
        border-radius: 5px;
        display: flex;
        align-items: center;
        justify-content: center;
        text-decoration: none;
        font-size: 14px;
    }

    #open {
        background-color: darkred;
    }

    #js {
        width: 200px;
        height: 100px;
        margin: 20px;
        z-index: -1;
    }
</style>
<script>
  var copyOK = 0

  function copy () {
    document.getElementById('code').select()
    document.execCommand('Copy')
    document.getElementById('copy').innerText = '复制成功！' + (copyOK > 0 ? '+' + copyOK : '')
    copyOK++
    document.getElementById('open').focus()
  }

</script>
</html>
